﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace Demo_jQuery_pager_plugin
{
    /// <summary>
    /// jQueryPagerByPageIndex 的摘要说明
    /// </summary>
    public class jQueryPagerByPageIndex : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            String strcurrPageIndex = context.Request["pageIndex"].ToString();

            //SqlParameter[] sqlparm = {  
            //                             new SqlParameter("@currPage",Int32.Parse(strcurrPageIndex)),
            //                             new SqlParameter("@showColumn","*"),
            //                             new SqlParameter("@tabName","EASYBUY_PRODUCT"),
            //                             new SqlParameter("@strCondition",String.Empty),
            //                             new SqlParameter("@ascColumn","EP_NAME"),
            //                             new SqlParameter("@bitOrderType",0),
            //                             new SqlParameter("@pkColumn","EP_ID"),
            //                             new SqlParameter("@pageSize",4)
            //                         };
            //DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.ConnectionString, "PageResult", sqlparm).Tables[0];

            SqlParameter[] sqlparm = {  
                                         new SqlParameter("@pageIndex",Int32.Parse(strcurrPageIndex)),
                                         new SqlParameter("@pageSize",5),
                                     };
            DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionString, "sp_PageSplit_PRODUCT", sqlparm);

            System.Text.StringBuilder sb = new System.Text.StringBuilder(1000);
            sb.Append("<table border='1' class='tb_procudt' cellpadding='0' cellspacing='0'>");
            sb.Append("<thead style='background-color:#aaccff'><tr>");
            sb.Append("<th>商品名称</th><th>价格</th><th>商品图片</th><th>商品描述</th><th>库存</th>");
            sb.Append("</tr></thead>");
            sb.Append("<tbody>");

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    sb.Append("<tr>");
                    sb.Append("<td style='background-color:#ccc;width:15%;'>" + row["EP_NAME"].ToString() + "</td>");
                    sb.Append("<td style='background-color:#ccc;width:15%;'>" + String.Format("{0:C0}", Int32.Parse(row["EP_PRICE"].ToString())) + "</td>");
                    sb.Append("<td style='background-color:#ccc;width:25%;'>" + row["EP_FILE_NAME"].ToString() + "</td>");
                    sb.Append("<td style='background-color:#ccc;width:35%;'>" + row["EP_DESCRIPTION"].ToString() + "</td>");
                    sb.Append("<td style='background-color:#ccc;width:10%;'>" + row["EP_STOCK"].ToString() + "</td>");
                    sb.Append("</tr>");
                }
            }
            sb.Append("</tbody>");
            sb.Append("</table>");

            context.Response.Write(sb.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}